import httplib, urllib

class Uplink:
    connection = None

    def __init__(self,url):
        self.url = url
        self.connection = httplib.HTTPConnection(url)

    def reconnect(self):
        self.connection = httplib.HTTPConnection(self.url)

    def __del__(self):
        try:
            self.connection.close()
        except:
            pass

    def POST(self,path,params_dict):
        params = urllib.urlencode(params_dict)
        headers = {"Content-type": "application/x-www-form-urlencoded"}
        self.connection.request("POST", path, params, headers)
        response = self.connection.getresponse()
        data = response.read()
        return response.status, data

    def GET(self,path):
        self.connection.request("GET", path)
        result = self.connection.getresponse()
        data = result.read()
        return result.status, data

    def store_file(self,url,response):
        f = open(url,'wb')
        f.write(response)
        f.close()








